import numpy
import math
import scipy
import scipy.io
import scipy.misc
import scipy.cluster
import scipy.cluster.vq
import matplotlib
import matplotlib.pyplot
import os
import IPython
import IPython.parallel
import itertools
import random
import sklearn
import sklearn.decomposition
import sklearn.manifold
import sklearn.cluster
import sklearn.feature_extraction
import sklearn.feature_extraction.text
base_path = "/u/mlrobert/code/local/2013_drawing_assistant/data/"
num_thetas = 8
filter_path = base_path+"filters/gabor/num_thetas=08/"
tmp = []
for theta_index in range(num_thetas):
current_g_mat = scipy.io.loadmat(filter_path+"theta=%02d.mat" % theta_index)
current_g = current_g_mat["g"]
tmp.append(current_g)
g = numpy.array(tmp)
img_path = base_path+"renderings/bunny2/apparent_ridges.num_latitude_lines=20.num_longitude_lines=20/"
responses_base_path = base_path+"filter_responses/bunny2/apparent_ridges.num_latitude_lines=20.num_longitude_lines=20.gabor.num_thetas=08/"
debug_base_path = base_path+"debug/filter_responses/bunny2/apparent_ridges.num_latitude_lines=20.num_longitude_lines=20.gabor.num_thetas=08/"
def compute_gabor_filter_responses(img_name_ext):
import numpy
import scipy
import scipy.io
import scipy.misc
import os
import matplotlib
import matplotlib.pyplot
img_name = img_name_ext[:-4]
img_ext = img_name_ext[-4:]
img = scipy.misc.imread(img_path+img_name+img_ext).astype(numpy.float32)[:,:,0]
img = (255.0 - img) / 255.0
responses_path = responses_base_path+img_name+"/"
debug_path = debug_base_path+img_name+"/"
if not os.path.exists(responses_path):
os.makedirs(responses_path)
if not os.path.exists(debug_path):
os.makedirs(debug_path)
for theta_index in range(num_thetas):
F_img = numpy.fft.fft2(img)
F_img_centered = numpy.fft.fftshift(F_img)
F_img_centered_filtered = F_img_centered * g[theta_index]
F_img_centered_filtered_uncentered = numpy.fft.ifftshift(F_img_centered_filtered)
filter_response = numpy.fft.ifft2(F_img_centered_filtered_uncentered)
scipy.io.savemat("%stheta=%02d.mat" % (responses_path, theta_index), {"filter_response":filter_response}, oned_as="column")
matplotlib.pyplot.clf();
matplotlib.pyplot.imshow(numpy.abs(filter_response), interpolation="nearest");
matplotlib.pyplot.colorbar();
matplotlib.pyplot.savefig("%stheta=%02d.png" % (debug_path, theta_index));
matplotlib.pyplot.clf();
img_names_exts = sorted(os.listdir(img_path))
compute_gabor_filter_responses(img_names_exts[0])
client = IPython.parallel.Client()
directView = client[:]
directView["num_thetas"] = num_thetas
directView["img_path"] = img_path
directView["responses_base_path"] = responses_base_path
directView["debug_path"] = debug_path
directView["g"] = g
asyncResult = directView.map_async(compute_gabor_filter_responses, img_names_exts)
print asyncResult.progress
print asyncResult.ready()
32 True
result = asyncResult.get()
print result
[None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None]